<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>数据分组</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
  </style>
</head>
<!-- groupBy", "groupByToMap" -->

<body>
  <div></div>
</body>
<script>
  "use strict"; {
    let arr1 = [{
      type: 'clothes',
      value: '👔',
    }, {
      type: 'clothes',
      value: '👕',
    }, {
      type: 'clothes',
      value: '👗',
    }, {
      type: 'animal',
      value: '🐷',
    }, {
      type: 'animal',
      value: '🐸',
    }, {
      type: 'animal',
      value: '🐒',
    }];

    // 方法一:
    let t1 = () => {
      let groupedBy = {};
      for (let item of arr1) {
        groupedBy[item.type] ? groupedBy[item.type].push(item) : groupedBy[item.type] = [item]
      }
      console.table(groupedBy)
    }
    // 方法二: https://mp.weixin.qq.com/s/U9stOyfVEpiYkRBycE1OOg
    /* 
    浏览器目前还不支持
    Array.prototype.groupBy
      参数1：数组遍历到的当前对象
      参数2：index 索引
      参数3：原数组
    
    */
  };
</script>

</html>